from datetime import datetime
import time
import requests
import json,getopt,sys

opts,args = getopt.getopt(sys.argv[1:],"f:")
for opt,arg in opts:
    if opt in ("-f"):
        line1 = arg

def send_to_qyweixin(line):
    # 你的 Webhook URL
    webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=abc293fb-5657-4580-8a88-9fb29e87d6cf"

    # 消息内容
    data = {
        "msgtype": "text",
        "text": {
            "content": str(line)
        }
    }

    # 发送请求
    response = requests.post(webhook_url, json=data)

    # 输出结果
    print(response.json())
line_list = []
while True:
    # 获取当前时间
    now = datetime.now()

    # 格式化为常见字符串（年-月-日 时:分:秒）
    current_time = now.strftime("%Y-%m-%d %H:%M:%S")
    print("当前时间：", current_time)

    dt_object = datetime.strptime(current_time, "%Y-%m-%d %H:%M:%S")
    timestamp = dt_object.timestamp()
    # print("转换后的时间戳：", timestamp)

    # 读取整个文件内容
    helioslog = r"C:\Users\Public\Documents\Sifary\Helios\Log\Helios_net.log"
    with open(helioslog, "r") as file:
        _content = file.readlines()  # 全部内容作为字符串
        content = _content[-400:]


    for line in content:
        if "10054" in line:
            # print(line)
            if line not in line_list:
                line_list.append(line)
                send_to_qyweixin(line1)
                send_to_qyweixin(line)

    time.sleep(10)

